import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
const $time 			= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms: [
			{ label: '操作人',	name: 'operator_id',			type:'select',	loading:true },
			{ label: '操作时间',	names: ['start_date', 'end_date'], 	type:'date-range', 	loading:true,	format:1 },
		],
		stat: {first_num:'',second_num:''}
	}
	model = {}
	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{
			const arr = f.duration['2-date']()
			this.resetModel = { start_date: arr[0], end_date: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			this.fetch()
		})
		
	}
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 操作人
			$fn.setRow( forms, 'operator_id', await f.getCache({ api:'employee' }) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'specimen/doubleStat',{ callback:({stat})=> $fn.hasArray(stat) && this.setState({stat:stat[0]}) })
	
	controls = () => [
		Controls.exports.call(this, 'specimen/doubleStat'),
		Controls.back.call(this,{refresh:true} ),   														// 返回
	]
	
	// 表单
	cols = [
		{ title: '操作人',			dataIndex: 'operator_name', 		...$fn.table.name },
		{ title: '操作时间', 		dataIndex: 'operator_date', 		...$fn.table.time },
		{ title: '第一次录入',		dataIndex: 'first_num', 			width: 100 },
		{ title: '第二次录入', 		dataIndex: 'second_num', 			width: 100 },
		{ title: '双录入纠错', 		dataIndex: 'confirm_num', 			width: 100 },
	]

	render(){
		const { stat } = this.state
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this,{timeStr:'2-date'}) }
				{/* 表格 */}
				{ Table.call(this, {idStr:'id', suffix: ()=>(
					<>
						<span className='mr15'><span>第一次录入 :	</span> <b className='f14 c0'>{stat.first_num}</b></span>
						<span className='mr15'><span>第二次录入 :	</span> <b className='f14 c0'>{stat.second_num}</b></span>
						<span className='mr15'><span>双录入纠错 :	</span> <b className='f14 c0'>{stat.confirm_num}</b></span>
					</>
				)}) }
			</>
		)
	}
}

export default Index